a = int(input())
max_a = 0
if a > 999 and a <10000:
    for start in range(4) :
        for end in range(start , 4) :
            str_a = str(a)
            n = int(str_a[start:end + 1])
            d = 2
            flag = 1
            for d in range(2, int(n ** 0.5) + 1):
                if n % d == 0:
                    flag = 0
                d = d + 1
            if flag == 1 and n > max_a:
                max_a = n
if max_a <= 1:
        print(0)
else:
    print(max_a)
